<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */

require_once(APPPATH.'controllers/admin/applications.php');
class Leave_maintenance extends Applications
{
	public function __construct()
	{
		parent::__construct();

		/**
		 * @description check the session variables
		 */
		$this->M_login->session_check();

		/**
		 * @description the URL
		 */
		$this->bz_segment['URL'] = $this->M_functions->segment_create();
		$this->bz_segment['SITE_URL'] = site_url($this->bz_segment['URL']);

		/**
		 * @description access rights
		 */
		$this->access_rights = $this->M_menu->valid_check('db_default', $this->session->userdata('session_user_id'));
		$this->access_rights = array
			(
				'ADD' => in_array('add', $this->access_rights) ? TRUE : FALSE
				, 'EDIT' => in_array('edit', $this->access_rights) ? TRUE : FALSE
				, 'DELETE' => FALSE
			);

		/**
		 * @description initialize variables for database
		 */
		$this->tbl_attr = array
			(
				'TABLE' => array
					(
						'NAME' => 'hris_employee_leave_management'
						, 'NAME_ALIAS' => 'hris_employee_leave_management a'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('data__id', 'leave_management__id', 'valid_date_start')
							)
					)
				, 'TABLE_MODAL' => array
					(
						'NAME' => 'hris_employee_leave_management'
						, 'NAME_ALIAS' => 'hris_employee_leave_management b'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('data__id', 'leave_management__id', 'valid_date_start')
							)
					)
				, 'TABLE_EMPLOYEE_LEAVE_MANAGEMENT_HISTORY' => array
					(
						'NAME' => 'hris_employee_leave_management_history'
						, 'NAME_ALIAS' => 'hris_employee_leave_management_history c'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('id')
							)
					)
				, 'VIEW_DETAIL' => array
					(
						'HEADING' => array
							(
								$this->lang->line('hris_start').' '.$this->lang->line('hris_valid').' '.$this->lang->line('hris_date')
								, $this->lang->line('hris_end').' '.$this->lang->line('hris_valid').' '.$this->lang->line('hris_date')
								, $this->lang->line('hris_next').' '.$this->lang->line('hris_valid').' '.$this->lang->line('hris_date')
								, $this->lang->line('hris_total')
								, $this->lang->line('hris_used')
								, $this->access_rights['DELETE'] ? '&nbsp;' : NULL
							)
						, 'FIELDS' => 'data__id, leave_management__id, valid_date_start, valid_date_start as valid_date_start_show, valid_date_end, valid_date_next, total, used'
						, 'FIELDS_EDIT' => 'valid_date_start_show'
						, 'FIELDS_ORDER' => 'valid_date_start'
					)
				, 'VIEW_MODAL_DETAIL' => array
					(
						'HEADING' => array
							(
								$this->lang->line('hris_total') .'<br />(' . $this->lang->line('hris_old').')'
								, $this->lang->line('hris_total') .'<br />(' . $this->lang->line('hris_new').')'
								, $this->lang->line('hris_used') .'<br />(' . $this->lang->line('hris_old').')'
								, $this->lang->line('hris_used') .'<br />(' . $this->lang->line('hris_new').')'
								, $this->lang->line('hris_date')
								, $this->lang->line('hris_note')
								, $this->access_rights['DELETE'] ? '&nbsp;' : NULL
							)
						, 'FIELDS' => 'id, total_old, total_new, used_old, used_new, date, notes'
						, 'FIELDS_EDIT' => ''
						, 'FIELDS_ORDER' => 'date desc'
					)
				, 'FORM' => array
					(
						'FIELDS' => ''
						, 'FIELDS_ORDER' => ''
						, 'COLUMN' => 4
						, 'COLUMN_JOIN' => 2
					)
				, 'FORM_MODAL' => array
					(
						'HEADING' => $this->lang->line('hris_modal')
						, 'FIELDS' => 'data__id, leave_management__id, valid_date_start, valid_date_start as valid_date_start_show, valid_date_end, valid_date_next, total, used'
						, 'FIELDS_ORDER' => ''
						, 'COLUMN' => 4
						, 'COLUMN_JOIN' => 2
					)
				, 'URL' => array
					(
						'FORM' => $this->bz_segment['SITE_URL'].'/form'
						, 'VIEW' => $this->bz_segment['SITE_URL'].'/view'
					)
			);

		$this->tbl_viewdetail_attr = array
			(
				'VIEW_DETAIL' => array
					(
						'NAME' => $this->tbl_attr['TABLE_MODAL']['NAME_ALIAS']
						, 'PRIMARY' => $this->tbl_attr['TABLE_MODAL']['PRIMARY']
						, 'HEADING' => $this->tbl_attr['VIEW_DETAIL']['HEADING']
						, 'FIELDS' => array
							(
								'NAME' => $this->tbl_attr['VIEW_DETAIL']['FIELDS']
								, 'CAPTION' => $this->tbl_attr['VIEW_DETAIL']['FIELDS_EDIT']
								, 'ORDER' => $this->tbl_attr['VIEW_DETAIL']['FIELDS_ORDER']
							)
						, 'JAVASCRIPT' => array
							(
								'VIEWLIST_GENERATE' => array
									(
										'JS_FUNCTION_NAME' => 'js_modaldialog_data_put'
										, 'JS_FUNCTION_PARAMETERS' => '"'.$this->bz_segment['SITE_URL'].'/ajx_live_form_detail", "frm_modal", "txt0", "txt72", "js_modal_functions", "'.$this->bz_segment['SITE_URL'].'", "ajx_modal_data_", "put"'
									)
							)
					)

				, 'VIEW_MODAL_DETAIL' => array
					(
						'NAME' => $this->tbl_attr['TABLE_EMPLOYEE_LEAVE_MANAGEMENT_HISTORY']['NAME_ALIAS']
						, 'PRIMARY' => $this->tbl_attr['TABLE_EMPLOYEE_LEAVE_MANAGEMENT_HISTORY']['PRIMARY']
						, 'HEADING' => $this->tbl_attr['VIEW_MODAL_DETAIL']['HEADING']
						, 'FIELDS' => array
							(
								'NAME' => $this->tbl_attr['VIEW_MODAL_DETAIL']['FIELDS']
								, 'CAPTION' => $this->tbl_attr['VIEW_MODAL_DETAIL']['FIELDS_EDIT']
								, 'ORDER' => $this->tbl_attr['VIEW_MODAL_DETAIL']['FIELDS_ORDER']
							)
						, 'JAVASCRIPT' => array
							(
								'VIEWLIST_GENERATE' => array
									(
										'JS_FUNCTION_NAME' => ''
										, 'JS_FUNCTION_PARAMETERS' => ''
									)
							)
					)
			);

		/**
		 * @description template lite variables
		 */
		$this->bz_tlite_var['CACHE_PATH'] = $this->bz_tlite_var['SESSION']['USER_ID'].'|'.str_replace('/', '|', $this->bz_segment['URL']);
		$this->bz_tlite_var['CACHE'] = array
			(
				'PUBLIC' => $this->bz_tlite_var['SESSION']['USER_ID']
				, 'PRIVATE' => array
					(
						'GLOBAL' => $this->bz_tlite_var['CACHE_PATH']
						, 'FORM' => $this->bz_tlite_var['CACHE_PATH'].'|form'
					)
			);
	}


	/**
	 * @function index()
	 * @description main controller
	 */
	public function index()
	{
		/**
		 * @description choose which controller to show
		 */
		redirect($this->tbl_attr['URL']['FORM']);
	}


	/**
	 * @function form()
	 * @description form for data entry
	 */
	public function form()
	{
		if ($this->web_data['BISKITZ']['HEADER']['BROWSER_SUPPORTED'] == '')
		{
			/**
			 * @description if the user has ADD or EDIT access, show the form!
			 */
			if ($this->access_rights['ADD'] OR $this->access_rights['EDIT'])
			{
				/**
				 * @description if there isn't any css/ajax cache, build it! else show cache!
				 */
				if ( ! $this->bz_tlite->is_cached($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']))
				{
					/**
					 * @section begin page init
					 */
						/**
						 * @description show the menu
						 */
						$menu = $this->M_menu->shows();
						$this->web_data['JAVASCRIPT_MENU'] = $menu['JAVASCRIPT_MENU'];
						$this->web_data['PAGE']['MENU'] = $menu['PAGE']['MENU'];

						/**
						 * @description init the css and the ajax needed
						 */
						$css_files = array
							(
								array('layout' => 'screen')
								, array('tipsy/tipsy' => 'screen')
								, array('validate/validate' => 'screen')
								, array('form_icon_bar' => 'screen')
								, array('nanoscroller/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
								, array('shortcut_bar' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
								, array('jqModal/jqModal' => 'screen')
								, array('ddm/multi-ddm' => 'screen')
							);
						$js_files = array
							(
								'js/plugins/ddm' => array('jquery.multi-ddm.pack')
								, 'js/plugins/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? array('jquery.nanoscroller.min', 'overthrow.min') : NULL
								, 'js/plugins/validate' => array('jquery.validate.pack', 'additional-methods', 'jquery.metadata')
								, 'js/plugins/tipsy' => array('jquery.tipsy.pack')
								, 'js/plugins/jqModal' => array('jqModal.pack')
								, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_FUNCTIONS_PATH'] => array('common', 'form', 'error', 'modaldialog')
								, 'themes/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'].'/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_PATH'] => array('common')
							);
					/**
					 * @section end page init
					 */


					/**
					 * @section begin form initialize
					 */
						/**
						 * @description load the models
						 */
						$this->load->model('admin/hris/HRIS_M_live_data');


						/**
						 * @description initialize the form elements
						 */
						$form_content_join[] = array
							(
								'<b>'.$this->lang->line('hris_company_name').'</b>'
								, array
									(
										'data' => form_dropdown
											(
												'txtinput[0]'
												, $this->HRIS_M_live_data->combo_fill('db_default', 'company_profile', '', 'RECURSIVE', array(), FALSE)
												, ''
												, 'id="txt0" class="{validate: {required: true}}"'
											)
										, 'colspan' => 3
									)
							);

						$form_content[] = array
							(
								'<b>'.$this->lang->line('hris_type').'</b>'
								, form_dropdown
									(
										'txtinput[1]'
										, array('' => $this->lang->line('hris_choose'))
										, ''
										, 'id="txt1" class="{validate: {required: true}}"'
									)

								, '<b>'.$this->lang->line('hris_employee_data').'&nbsp;'.$this->lang->line('hris_status').'</b>'
								, form_dropdown
									(
										'txtinput[2]'
										, $this->HRIS_M_live_data->combo_fill('db_default', 45, '', 'NORMAL', array(), FALSE, '', FALSE)
										, ''
										, 'id="txt2" class="{validate: {required: true}}"'
									)
							);

						$form_content_join[] = array
							(
								'<b>'.$this->lang->line('hris_employee_data').'</b>'
								, array
									(
										'data' => form_dropdown
											(
												'txtinput[3]'
												, array('' => $this->lang->line('hris_choose'))
												, ''
												, 'id="txt3" class="{validate: {required: true}} latest_object"'
											)
										, 'colspan' => 3
									)
							);

						/**
						 * @description create the form and elements
						 */
						$this->table->clear();
						$table_template = array('table_open' => '<table class = "plain">');
						$this->table->set_template($table_template);

						$form[] = $this->table->make_columns($form_content_join[0], $this->tbl_attr['FORM']['COLUMN_JOIN']);
						$form[] = $this->table->make_columns($form_content[0], $this->tbl_attr['FORM']['COLUMN']);
						$form[] = $this->table->make_columns($form_content_join[1], $this->tbl_attr['FORM']['COLUMN_JOIN']);

						$form_content = $this->table->generate(array_merge($form[0], $form[1], $form[2]));
					/**
					 * @section end form initialize
					 */



					/**
					 * @section begin generate template variables
					 */
						/**
						 * @description css and ajax
						 */
						$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
						$this->web_data['PAGE']['JAVASCRIPT_FILES'] = $this->M_template->js_generate($js_files);

						/**
						 * @description initialize the additional javascript
						 */
						$this->web_data['JAVASCRIPT'] .= '
							<script>
								var js_modal_functions =
								"
									$(\"#btn_modal_save\").click
										(function()
										{
											js_form_action_validate
											(
												\"'.$this->bz_segment['SITE_URL'].'\", \"ajx_modal_\", \"update\", \"\"
												, \"#frm_modal\", \"#process_modaldialog\", \"#error_message_modaldialog\"
												, \"validate\"
											);

											$(\"#txt72\").focus().select();
										});
								";

								js_modaldialog_popup =
								"
									js_modaldialog_show
									(
										\"'.$this->bz_segment['SITE_URL'].'/ajx_live_form_detail/new/\" + $(\"#txt0\").val()
										, \"frm_modal\"
										, \"txt0\", \"txt72\"
										, js_modal_functions
									);
								";

								js_view_detail_generate =
								"
									js_form_action
									(
										\"'.$this->bz_segment['SITE_URL'].'\", \"ajx_data_\", \"put\", \"\"
										, \"#frm_header\", \"#process\", \"#error_message\"
									);
								";


								$(function()
								{
									$("#txt0").change
										(function()
										{
											$("#txt1, #txt3").empty()
												.append( $("<option></option>").val("").html("'.$this->lang->line('hris_choose').'") );
											$("#content_replace").replaceWith("<div id=\"content_replace\"></div>");

											if ($(this).val() != "")
											{
												js_form_action
												(
													"'.$this->bz_segment['SITE_URL'].'", "ajx_live_", "combo_put", "leave_management_company/1"
													, "#frm_header", "#process", "#error_message"
												);
											}
										});

									$("#txt1, #txt2").change
										(function()
										{
											$("#txt3").empty()
												.append( $("<option></option>").val("").html("'.$this->lang->line('hris_choose').'") );
											$("#content_replace").replaceWith("<div id=\"content_replace\"></div>");

											if ($(this).val() != "")
											{
												js_form_action
												(
													"'.$this->bz_segment['SITE_URL'].'", "ajx_live_", "combo_put", "employee_data/3"
													, "#frm_header", "#process", "#error_message"
/*
													, 0
													, js_view_detail_generate
*/
												);
											}
										});

									$("#txt3").change
										(function()
										{
											if ($(this).val() != "")
											{
												eval(js_view_detail_generate);
											}
											else
											{
												$("#content_replace").replaceWith("<div id=\"content_replace\"></div>");
											}
										});

									$("#txt0").focus().select();
						';

						if ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error')
						{
							$this->web_data['JAVASCRIPT'] .= '$(".nano").nanoScroller({preventPageScrolling: true});';
						}

						$this->web_data['JAVASCRIPT'] .= '
								});
							</script>
						';

						/**
						 * @description menu descriptions
						 */
						$this->web_data['PAGE']['DETAIL'] = $this->M_menu->detail();

						/**
						 * @description form dialogs
						 */
						$this->web_data['PAGE']['FORM'] = array
							(
								'OPEN' => form_open('', array('id' => 'frm_header', 'onSubmit' => 'return false'), '')
								, 'CONTENT' => $form_content
							);

						/**
						 * @description notes
						 */
						$this->web_data['PAGE']['NOTES'] = array
							(
								'USE' => 'TRUE'
								, 'MESSAGE' => array
									(
										'SHORTCUTS' => $this->lang->line('notes_shortcuts')
										, 'ADDITIONAL' => $this->lang->line('notes_additional_modaldialog')
									)
							);
					/**
					 * @section end generate template variables
					 */
				}


				/**
				 * @description log the action!
				 */
				$this->M_log->write('db_default', sprintf($this->lang->line('log_form_access'), $this->router->class, 'form'));
			}
			else
			{
				/**
				 * @description doesn't have ADD or EDIT access? redirect to desktop
				 */
				redirect('admin/desktop');
			}



		}
		else
		{
			/**
			 * @section Browser NOT Supported
			 */
				/**
				 * @description browser not supported message error
				 */
				$css_files = array(array('layout' => 'screen'));


				/**
				 * @section begin generate template variables
				 */
					/**
					 * @description css and ajax
					 */
					$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
				/**
				 * @section end generate template variables
				 */
		}



		/**
		 * @description output template variables
		 */
		$this->bz_tlite->assign('WEB_DATA', $this->web_data);


		/**
		 * @section begin output
		 */
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['HEADER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['MENU'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_DESCRIPTION'], $this->bz_tlite_var['CACHE']['PRIVATE']['GLOBAL']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM_ICON_BAR'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_SHORTCUT_BAR'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);

		$this->bz_tlite->cache = FALSE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT_EXTEND']);

		$this->bz_tlite->cache = TRUE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER_END'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		/**
		 * @section end output
		 */
	}



/**
 * @section AJAX Action Section
 */

	/**
	 * @function ajx_data_put()
	 * @description get the data from database and put them to the form via ajax!
	 */
	public function ajx_data_put()
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'])
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_live_data', 'admin/hris/HRIS_M_live_data'));
			/**
			 * @description load the helper
			 */
			$this->load->helper('viewlist');


			$return_value = $this->M_live_data->put
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME_ALIAS']
					, array
						(
							'data__id' => $this->input->post('txtinput[3]')
							, 'leave_management__id' => $this->input->post('txtinput[1]')
							, 'activated' => 'Yes'
						)
					, '"'.$this->input->post('txtinput[0]').'", "'.$this->input->post('txtinput[1]').'", "'.$this->input->post('txtinput[2]').'", "'.$this->input->post('txtinput[3]').'"'
					, 0, 'log_form_edit', 'form'

					, 'js_action_data_detail'
					, array
						(
							'FUNCTION_NAME' => 'detail_generate'
							, 'FUNCTION_ATTR' => array
								(
									'db_default'
									, $this->tbl_viewdetail_attr['VIEW_DETAIL']
									, array
										(
											'data__id' => $this->input->post('txtinput[3]')
											, 'leave_management__id' => $this->input->post('txtinput[1]')
											, 'activated' => 'Yes'
										)
									, $this->tbl_viewdetail_attr['VIEW_DETAIL']['JAVASCRIPT']['VIEWLIST_GENERATE']
								)
						)
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



/**
 * @section AJAX MODAL Action Section
 */

	/**
	 * @function ajx_modal_data_put()
	 * @description get the data from database and put them to the form via ajax!
	 */
	public function ajx_modal_data_put($prm_data_id = '', $prm_leave_management_id = '', $prm_valid_date_start = '')
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'] && trim($prm_data_id) != '' && trim($prm_leave_management_id) != '' && trim($prm_valid_date_start) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_live_data', 'admin/hris/HRIS_M_live_data'));
			/**
			 * @description load the helper
			 */
			$this->load->helper('viewlist');


			$return_value = $this->M_live_data->put
				(
					'db_default'
					, $this->tbl_attr['TABLE_MODAL']['NAME_ALIAS']
					, array('data__id' => $prm_data_id, 'leave_management__id' => $prm_leave_management_id, 'valid_date_start' => $prm_valid_date_start)
					, $this->tbl_attr['FORM_MODAL']['FIELDS']
					, 70
					, 'log_form_edit'
					, 'modal'

					, 'js_action_data_detail'
					, array
						(
							'FUNCTION_NAME' => 'detail_generate'
							, 'FUNCTION_ATTR' => array
								(
									'db_default'
									, $this->tbl_viewdetail_attr['VIEW_MODAL_DETAIL']
									, array('data__id' => $prm_data_id, 'leave_management__id' => $prm_leave_management_id, 'valid_date_start' => $prm_valid_date_start)
									, $this->tbl_viewdetail_attr['VIEW_MODAL_DETAIL']['JAVASCRIPT']['VIEWLIST_GENERATE']
								)
						)
					, FALSE, ''
					, FALSE
					, 'modal_content_replace'
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_modal_update()
	 * @description update the detail data
	 */
	public function ajx_modal_update()
	{
		if ($this->input->is_ajax_request() && ($this->access_rights['ADD'] OR $this->access_rights['EDIT']))
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/M_live_data');
			/**
			 * @description load the helper
			 */
			$this->load->helper('viewlist');


			$data = array
				(
					'total' => $this->input->post('txtinput[76]')
					, 'used' => $this->input->post('txtinput[77]')
				);

			$detail_return = $this->M_live_data->update
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME']
					, array('data__id' => $this->input->post('txtinput[70]'), 'leave_management__id' => $this->input->post('txtinput[71]'), 'valid_date_start' => $this->input->post('txtinput[72]'), 'activated' => 'Yes')
					, $data
					, 'modal'
					, 'js_action_update'
					, ''
					, FALSE
				);


			/**
			 * @description process the employee_leave_management_history
			 */
			$header['ID'] = $this->M_database->max_id('db_default', 'hris_employee_leave_management_history', 'id');
			$this->M_live_data->update
				(
					'db_default'
					, 'hris_employee_leave_management_history'
					, array('id' => $header['ID'])
					, array('notes' => $this->input->post('txtinput[78]'))
					, 'modal'
					, 'js_action_update'
					, ''
					, FALSE
				);


			$modaldialog_status = 'modaldialog_close_auto';

			/**
			 * @description generate the viewlist live!
			 */
			$return_value = array
				(
					'js_action_modal_insert'
					, $detail_return[1], array()

					/**
					 * @description the header id in the MODAL form, use it to sync with the main form
					 */
					, 71

					/**
					 * @description put the header data to main form after success inserting detail data
					 */
					, array()

					/**
					 * @description generate the detail view list, LIVE!
					 */
					, array
						(
							'content_replace'
							, detail_generate
								(
									'db_default'
									, $this->tbl_viewdetail_attr['VIEW_DETAIL']
									, array
										(
											'data__id' => $this->input->post('txtinput[70]')
											, 'leave_management__id' => $this->input->post('txtinput[71]')
											, 'activated' => 'Yes'
										)
									, $this->tbl_viewdetail_attr['VIEW_DETAIL']['JAVASCRIPT']['VIEWLIST_GENERATE']
								)
						)

					/**
					 * @description trigger the dialog to be automatically closed
					 */
					, array($modaldialog_status)
				);



			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



/**
 * @section AJAX Live Section
 */

	/**
	 * @function ajx_live_combo_put
	 * @description get the data and put them in combobox
	 */
	public function ajx_live_combo_put($prm_module_table = '', $prm_object_start = '0', $prm_where_key = '', $prm_selected_value = '')
	{
		if ($this->input->is_ajax_request() && trim($prm_module_table) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/hris/HRIS_M_live_data');


			$table['TYPE'] = 'NORMAL';
			$table['CHOOSE_SHOW'] = TRUE;
			$table['QUERY_SPECIAL'] = FALSE;
			switch ($prm_module_table)
			{
				case 'leave_management_company':
					$table['NAME'] = 'hris_attendance_leave_management_company';
					$table['WHERE'] = array('company__id' => $this->input->post('txtinput[0]'), 'leave_management__id in ' => '(select id from bz_hris_attendance_leave_management where request_type__id = 217)');
					$table['QUERY_SPECIAL'] = TRUE;
					break;

				case 'employee_data':
					$table['NAME'] = 'hris_employee_data';
					$table['WHERE'] = array
						(
							'EMPLOYEE_NO_DATA_ID' => TRUE
							, 'DATA' => array('id in ' => '(select a.data__id from bz_hris_employee_company a, bz_hris_employee_leave_management b where a.data__id = b.data__id and company__id = '.$this->input->post('txtinput[0]').' and employee_status__id = '.$this->input->post('txtinput[2]').' and activated = "Yes" and leave_management__id = '.$this->input->post('txtinput[1]').')')
						);
					$table['QUERY_SPECIAL'] = TRUE;
					break;
			}


			if ( ! isset($return_value))
			{
				$return_value = $this->HRIS_M_live_data->combo_fill('db_default', $table['NAME'], $prm_object_start, $table['TYPE'], $table['WHERE'], FALSE, $prm_selected_value, $table['CHOOSE_SHOW'], $table['QUERY_SPECIAL']);
			}


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_live_form_detail
	 * @description generate the detail form via ajax
	 */
	public function ajx_live_form_detail()
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'])
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_layout', 'admin/hris/HRIS_M_live_data'));
			/**
			 * @description load the helper
			 */
			$this->load->helper('viewlist');


			/**
			 * @section begin form MODAL initalize
			 */
				/**
				 * @description create the MODAL form and elements
				 */
				$form_modal_content[] = array
					(
						'<b>'.$this->lang->line('hris_start').' '.$this->lang->line('hris_valid').' '.$this->lang->line('hris_date').'</b>'
						, form_input
							(
								array
								(
									'type' => 'hidden'
									, 'name' => 'txtinput[70]', 'id' => 'txt70'
									, 'size' => '20', 'maxlength' => '20'
									, 'readOnly' => 'readOnly', 'class' => 'read_only do_not_change'
								)
							)
							. form_input
								(
									array
									(
										'type' => 'hidden'
										, 'name' => 'txtinput[71]', 'id' => 'txt71'
										, 'size' => '18', 'maxlength' => '18'
										, 'readOnly' => 'readOnly', 'class' => 'read_only do_not_change'
									)
								)
							. form_input
								(
									array
									(
										'type' => 'hidden'
										, 'name' => 'txtinput[72]', 'id' => 'txt72'
										, 'size' => '10', 'maxlength' => '10'
										, 'readOnly' => 'readOnly', 'class' => 'read_only do_not_change'
									)
								)
							. '<span id="txt73"></span>'

						, '<b>'.$this->lang->line('hris_end').' '.$this->lang->line('hris_valid').' '.$this->lang->line('hris_date').'</b>'
						, '<span id="txt74"></span>'

						, '<b>'.$this->lang->line('hris_next').' '.$this->lang->line('hris_valid').' '.$this->lang->line('hris_date').'</b>'
						, '<span id="txt75"></span>'

						, '&nbsp;'
						, '&nbsp;'

						, '<b>'.$this->lang->line('hris_total').'</b><br /><small>'.$this->lang->line('fields_required').'</small>'
						, form_input
							(
								array
								(
									'name' => 'txtinput[76]', 'id' => 'txt76'
									, 'size' => '5', 'maxlength' => '5'
									, 'class' => '{validate: {required: true, number: true, min: 0}} input_right'
								)
							)

						, '<b>'.$this->lang->line('hris_used').'</b><br /><small>'.$this->lang->line('fields_required').'</small>'
						, form_input
							(
								array
								(
									'name' => 'txtinput[77]', 'id' => 'txt77'
									, 'size' => '5', 'maxlength' => '5'
									, 'class' => '{validate: {required: true, number: true, min: 0}} input_right'
								)
							)
					);

				$form_modal_content_join[] = array
					(
						array('data' => '<b>'.$this->lang->line('hris_note').'</b><br /><small>'.$this->lang->line('fields_required').'</small>', 'valign' => 'top')
						, array
							(
								'data' => form_textarea
									(
										array
										(
											'name' => 'txtinput[78]', 'id' => 'txt78'
											, 'cols' => '45', 'rows' => '3'
											, 'class' => '{validate: {required: true}}'
										)
									)
								, 'colspan' => 3
							)
					);


				$form_modal_content[] = array
					(
						'&nbsp;'
						, form_submit
							(
								array('id' => 'btn_modal_save')
								, $this->lang->line('button_save')
							)
					);
				/**
				 * @description create the form MODAL and elements
				 */
				$this->table->clear();
				$table_template = array('table_open' => '<table id = "table_modaldialog" width = "100%">');
				$this->table->set_template($table_template);

				$form[] = $this->table->make_columns($form_modal_content[0], $this->tbl_attr['FORM_MODAL']['COLUMN']);
				$form[] = $this->table->make_columns($form_modal_content_join[0], $this->tbl_attr['FORM_MODAL']['COLUMN_JOIN']);
				$form[] = $this->table->make_columns($form_modal_content[1], $this->tbl_attr['FORM_MODAL']['COLUMN']);

				$form_modal_content = $this->table->generate(array_merge($form[0], $form[1], $form[2]));


				/**
				 * @section Leave Management History
				 */
				$form_modal_content .= '<div id="modal_content_replace"></div>';
			/**
			 * @section end form MODAL initalize
			 */


			/**
			 * @section begin generate template variables
			 */
			$return_value = array
				(
					/**
					 * @description form modal dialogs
					 */
					'FORM_MODAL' => array
						(
							'OPEN' => form_open('', array('id' => 'frm_modal', 'onSubmit' => 'return false'), '')
							, 'TITLE' => $this->tbl_attr['FORM_MODAL']['HEADING']
							, 'CONTENT' => $form_modal_content
						)

					/**
					 * @description notes modaldialog
					 */
					, 'NOTES_MODAL' => array
						(
							'USE' => 'TRUE'
							, 'MESSAGE' => array
								(
									'SHORTCUTS' => $this->lang->line('notes_modaldialog_shortcuts')
									, 'ADDITIONAL' => ''
								)
						)
				);
			/**
			 * @section end generate template variables
			 */


			$return_value = $this->M_layout->modaldialog_generate($return_value);
			echo $return_value;
		}
	}



}

/** End of file leave_maintenance.php */
/** Location: ./biskitz_mpc/biskitz/controllers/admin/hris/attendance/management/leave_maintenance.php */
